﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="DutyEdit.aspx.cs" Inherits="Web.DutyEdit" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
	<meta content="ie=7" http-equiv="x-ua-compatible">
	<script src="Content/scripts/extjs/adapter/ext/ext-base.js"></script>
	<script src="Content/scripts/extjs/ext-all.js"></script>
	<!-- 日期时间控件 -->
	<script src="Content/scripts/My97DatePicker/WdatePicker.js"></script>
    <link href="Content/scripts/plugIn/Pagination/style.css" rel="stylesheet" type="text/css" />
    <link href="Content/scripts/plugIn/Pagination/core.css" rel="stylesheet" type="text/css" />
    <style>
    .header{font-size:18px;margin:24px auto 6px auto;}
    a{margin:auto 6px;}
    </style>
    <script>
        function fnSave() {
            var dutyDate = document.getElementById("txtDutyDate").value;
            if (dutyDate == "") { alert("请选择值班日期!"); return; }
            var dutyList = [];
            var isChoose = false;
            var row, objCheck;

            //#region 高管
            var tb = tbGaoGuan;
            for (var i = 0; i < tb.rows.length; i++) {
                row = tb.rows[i];
                objCheck = row.cells[0].getElementsByTagName("INPUT")[0];
                if (objCheck != null && objCheck.checked) {
                    dutyList.push({ DutyDate: dutyDate, DeptId: -1, EmpId: objCheck.value });
                    isChoose = true;
                }
            }
            //if (!isChoose) { alert("请选择值班高管!"); return; }
            //#endregion
            //#region 经理
            tb = tbJingLi;
            isChoose = false;
            for (var i = 0; i < tb.rows.length; i++) {
                row = tb.rows[i];
                objCheck = row.cells[0].getElementsByTagName("INPUT")[0];
                if (objCheck != null && objCheck.checked) {
                    dutyList.push({ DutyDate: dutyDate, DeptId: -2, EmpId: objCheck.value });
                    isChoose = true;
                }
            }
            //if (!isChoose) { alert("请选择值班经理!"); return; }
            //#endregion
            //#region 业务
            tb = tbYeWu;
            isChoose = false;
            for (var i = 0; i < tb.rows.length; i++) {
                row = tb.rows[i];
                objCheck = row.cells[0].getElementsByTagName("INPUT")[0];
                if (objCheck != null && objCheck.checked) {
                    dutyList.push({ DutyDate: dutyDate, DeptId: 18, EmpId: objCheck.value });
                    isChoose = true;
                }
            }
            //if (!isChoose) { alert("请选择业务部值班人员!"); return; }
            //#endregion
            //#region 行政
            tb = tbXingZheng;
            isChoose = false;
            for (var i = 0; i < tb.rows.length; i++) {
                row = tb.rows[i];
                objCheck = row.cells[0].getElementsByTagName("INPUT")[0];
                if (objCheck != null && objCheck.checked) {
                    dutyList.push({ DutyDate: dutyDate, DeptId: 21, EmpId: objCheck.value });
                    isChoose = true;
                }
            }
            //if (!isChoose) { alert("请选择行政中心值班人员!"); return; }
            //#endregion
            //#region 结算
            tb = tbJieSuan;
            isChoose = false;
            for (var i = 0; i < tb.rows.length; i++) {
                row = tb.rows[i];
                objCheck = row.cells[0].getElementsByTagName("INPUT")[0];
                if (objCheck != null && objCheck.checked) {
                    dutyList.push({ DutyDate: dutyDate, DeptId: 17, EmpId: objCheck.value });
                    isChoose = true;
                }
            }
            //if (!isChoose) { alert("请选择结算部值班人员!"); return; }
            //#endregion
            //#region 物流
            tb = tbWuLiu;
            isChoose = false;
            for (var i = 0; i < tb.rows.length; i++) {
                row = tb.rows[i];
                objCheck = row.cells[0].getElementsByTagName("INPUT")[0];
                if (objCheck != null && objCheck.checked) {
                    dutyList.push({ DutyDate: dutyDate, DeptId: 6, EmpId: objCheck.value });
                    isChoose = true;
                }
            }
            //if (!isChoose) { alert("请选择物流部值班人员!"); return; }
            //#endregion
            //#region 财务
            tb = tbCaiWu;
            isChoose = false;
            for (var i = 0; i < tb.rows.length; i++) {
                row = tb.rows[i];
                objCheck = row.cells[0].getElementsByTagName("INPUT")[0];
                if (objCheck != null && objCheck.checked) {
                    dutyList.push({ DutyDate: dutyDate, DeptId: 35, EmpId: objCheck.value });
                    isChoose = true;
                }
            }
            //if (!isChoose) { alert("请选择财务中心值班人员!"); return; }
            //#endregion
            //#region 产品
            tb = tbChanPing;
            isChoose = false;
            for (var i = 0; i < tb.rows.length; i++) {
                row = tb.rows[i];
                objCheck = row.cells[0].getElementsByTagName("INPUT")[0];
                if (objCheck != null && objCheck.checked) {
                    dutyList.push({ DutyDate: dutyDate, DeptId: 16, EmpId: objCheck.value });
                    isChoose = true;
                }
            }
            //if (!isChoose) { alert("请选择产品部值班人员!"); return; }
            //#endregion
            //#region 直营
            tb = tbZhiYing;
            isChoose = false;
            for (var i = 0; i < tb.rows.length; i++) {
                row = tb.rows[i];
                objCheck = row.cells[0].getElementsByTagName("INPUT")[0];
                if (objCheck != null && objCheck.checked) {
                    dutyList.push({ DutyDate: dutyDate, DeptId: 19, EmpId: objCheck.value });
                    isChoose = true;
                }
            }
            //if (!isChoose) { alert("请选择直营店值班人员!"); return; }
            //#endregion
            //#region 会议管理部
            tb = tbHuiYi;
            isChoose = false;
            for (var i = 0; i < tb.rows.length; i++) {
                row = tb.rows[i];
                objCheck = row.cells[0].getElementsByTagName("INPUT")[0];
                if (objCheck != null && objCheck.checked) {
                    dutyList.push({ DutyDate: dutyDate, DeptId: 37, EmpId: objCheck.value });
                    isChoose = true;
                }
            }
            //if (!isChoose) { alert("请选择会议管理部值班人员!"); return; }
            //#endregion
            Ext.Ajax.request({
                url: '/Duty.mvc/Add',
                method: 'POST',
                success: function (response, options) {
                    var responseMessage = Ext.util.JSON.decode(response.responseText);
                    if (responseMessage.Result) {
                        alert('数据保存成功！');
                        location.href = 'DutyList.aspx';
                    }
                    else {
                        alert('数据保存失败，请您重试！');
                    }
                },
                params: {
                    json: Ext.util.JSON.encode(dutyList)
                },
                failure: function (form, action) {
                    if (action.failureType == 'server') {
                        obj = Ext.util.JSON.decode(action.response.responseText);
                        alert(obj.errors.reason);
                    }
                    if (action.failureType == 'client') {
                        alert('数据不正确，请核对后重新操作');
                    }
                }
            });
        }
    </script>
</head>
<body>
<div class="header">值班编辑</div>
    <div style="float:left;">值班日期:<input class="Wdate" onClick="WdatePicker({readOnly:true})" id="txtDutyDate" name="txtDutyDate"/></div>
    <a class="buttonActive" href="javascript:fnSave();"><span>保存</span></a>
    <a class="button" href="javascript:history.back();"><span>返回</span></a>
    <form runat="server">
    <table class="list">
    <thead>
    <tr><th>轮值高管</th><th>值班经理</th><th>业务部</th><th>行政中心</th><th>结算部</th><th>物流中心</th><th>财务中心</th><th>产品部</th><th>直营店</th><th>会议管理部</th></tr></thead>
        <tr>
            <td>
                <asp:Repeater ID="rptGaoGuan" EnableViewState="False" Runat="server">
				    <HeaderTemplate>
						<table id="tbGaoGuan">
				    </HeaderTemplate>
				    <ItemTemplate>
					    <tr>
						    <td><input id="chkGaoGuan<%# Container.ItemIndex%>" type="checkbox" value='<%# DataBinder.Eval(Container.DataItem,"EmpId") %>'></td>
						    <td><label for="chkGaoGuan<%# Container.ItemIndex%>"><%# DataBinder.Eval(Container.DataItem, "Name")%></label></td>
					    </tr>
				    </ItemTemplate>
				    <FooterTemplate>
					    </table>
				    </FooterTemplate>
			    </asp:Repeater>
            </td>
            <td>
                <asp:Repeater ID="rptJingLi" EnableViewState="False" Runat="server">
				    <HeaderTemplate>
						<table id="tbJingLi">
				    </HeaderTemplate>
				    <ItemTemplate>
					    <tr>
						    <td><input id="chkJingLi<%# Container.ItemIndex%>" type="checkbox" value='<%# DataBinder.Eval(Container.DataItem,"EmpId") %>'></td>
						    <td><label for="chkJingLi<%# Container.ItemIndex%>"><%# DataBinder.Eval(Container.DataItem,"Name") %></label></td>
					    </tr>
				    </ItemTemplate>
				    <FooterTemplate>
					    </table>
				    </FooterTemplate>
			    </asp:Repeater>
            </td>
            <td>
                <asp:Repeater ID="rptYeWu" EnableViewState="False" Runat="server">
				    <HeaderTemplate>
						<table id="tbYeWu">
				    </HeaderTemplate>
				    <ItemTemplate>
					    <tr>
						    <td><input id="chkYeWu<%# Container.ItemIndex%>" type="checkbox" value='<%# DataBinder.Eval(Container.DataItem,"EmpId") %>'></td>
						    <td><label for="chkYeWu<%# Container.ItemIndex%>"><%# DataBinder.Eval(Container.DataItem,"Name") %></label></td>
					    </tr>
				    </ItemTemplate>
				    <FooterTemplate>
					    </table>
				    </FooterTemplate>
			    </asp:Repeater>
            </td>
            <td>
                <asp:Repeater ID="rptXingZheng" EnableViewState="False" Runat="server">
				    <HeaderTemplate>
						<table id="tbXingZheng">
				    </HeaderTemplate>
				    <ItemTemplate>
					    <tr>
						    <td><input id="chkXingZheng<%# Container.ItemIndex%>" type="checkbox" value='<%# DataBinder.Eval(Container.DataItem,"EmpId") %>'></td>
						    <td><label for="chkXingZheng<%# Container.ItemIndex%>"><%# DataBinder.Eval(Container.DataItem,"Name") %></label></td>
					    </tr>
				    </ItemTemplate>
				    <FooterTemplate>
					    </table>
				    </FooterTemplate>
			    </asp:Repeater>
            </td>
            <td>
                <asp:Repeater ID="rptJieSuan" EnableViewState="False" Runat="server">
				    <HeaderTemplate>
						<table id="tbJieSuan">
				    </HeaderTemplate>
				    <ItemTemplate>
					    <tr>
						    <td><input id="chkJieSuan<%# Container.ItemIndex%>" type="checkbox" value='<%# DataBinder.Eval(Container.DataItem,"EmpId") %>'></td>
						    <td><label for="chkJieSuan<%# Container.ItemIndex%>"><%# DataBinder.Eval(Container.DataItem,"Name") %></label></td>
					    </tr>
				    </ItemTemplate>
				    <FooterTemplate>
					    </table>
				    </FooterTemplate>
			    </asp:Repeater>
            </td>
            <td>
                <asp:Repeater ID="rptWuLiu" EnableViewState="False" Runat="server">
				    <HeaderTemplate>
						<table id="tbWuLiu">
				    </HeaderTemplate>
				    <ItemTemplate>
					    <tr>
						    <td><input id="chkWuLiu<%# Container.ItemIndex%>" type="checkbox" value='<%# DataBinder.Eval(Container.DataItem,"EmpId") %>'></td>
						    <td><label for="chkWuLiu<%# Container.ItemIndex%>"><%# DataBinder.Eval(Container.DataItem,"Name") %></label></td>
					    </tr>
				    </ItemTemplate>
				    <FooterTemplate>
					    </table>
				    </FooterTemplate>
			    </asp:Repeater>
            </td>
            <td>
                <asp:Repeater ID="rptCaiWu" EnableViewState="False" Runat="server">
				    <HeaderTemplate>
						<table id="tbCaiWu">
				    </HeaderTemplate>
				    <ItemTemplate>
					    <tr>
						    <td><input id="chkCaiWu<%# Container.ItemIndex%>" type="checkbox" value='<%# DataBinder.Eval(Container.DataItem,"EmpId") %>'></td>
						    <td><label for="chkCaiWu<%# Container.ItemIndex%>"><%# DataBinder.Eval(Container.DataItem,"Name") %></label></td>
					    </tr>
				    </ItemTemplate>
				    <FooterTemplate>
					    </table>
				    </FooterTemplate>
			    </asp:Repeater>
            </td>
            <td>
                <asp:Repeater ID="rptChanPing" EnableViewState="False" Runat="server">
				    <HeaderTemplate>
						<table id="tbChanPing">
				    </HeaderTemplate>
				    <ItemTemplate>
					    <tr>
						    <td><input id="chkChanPing<%# Container.ItemIndex%>" type="checkbox" value='<%# DataBinder.Eval(Container.DataItem,"EmpId") %>'></td>
						    <td><label for="chkChanPing<%# Container.ItemIndex%>"><%# DataBinder.Eval(Container.DataItem,"Name") %></label></td>
					    </tr>
				    </ItemTemplate>
				    <FooterTemplate>
					    </table>
				    </FooterTemplate>
			    </asp:Repeater>
            </td>
            <td>
                <asp:Repeater ID="rptZhiYing" EnableViewState="False" Runat="server">
				    <HeaderTemplate>
						<table id="tbZhiYing">
				    </HeaderTemplate>
				    <ItemTemplate>
					    <tr>
						    <td><input id="chkZhiYing<%# Container.ItemIndex%>" type="checkbox" value='<%# DataBinder.Eval(Container.DataItem,"EmpId") %>'></td>
						    <td><label for="chkZhiYing<%# Container.ItemIndex%>"><%# DataBinder.Eval(Container.DataItem,"Name") %></label></td>
					    </tr>
				    </ItemTemplate>
				    <FooterTemplate>
					    </table>
				    </FooterTemplate>
			    </asp:Repeater>
            </td>
            <td>
                <asp:Repeater ID="rptHuiYi" EnableViewState="False" Runat="server">
				    <HeaderTemplate>
						<table id="tbHuiYi">
				    </HeaderTemplate>
				    <ItemTemplate>
					    <tr>
						    <td><input id="chkHuiYi<%# Container.ItemIndex%>" type="checkbox" value='<%# DataBinder.Eval(Container.DataItem,"EmpId") %>'></td>
						    <td><label for="chkHuiYi<%# Container.ItemIndex%>"><%# DataBinder.Eval(Container.DataItem,"Name") %></label></td>
					    </tr>
				    </ItemTemplate>
				    <FooterTemplate>
					    </table>
				    </FooterTemplate>
			    </asp:Repeater>
            </td>
        </tr>
    </table>
    </form>
</body>
</html>